home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / sc_22.zip / READ.ME < prev    next >
Text File  |  1988-08-06  |  23KB  |  513 lines

  1.            Small C Compiler / Small Assembler
  2.                        User Notes
  3.  
  4.  
  5. COPYRIGHT NOTICES
  6.  
  7. Compiler:  Copyright 1982, 1983, 1985, 1988 J. E. Hendrix
  8. Library:   Copyright 1984 J. E. Hendrix, L. E. Payne
  9. Assembler: Copyright 1988 J. E. Hendrix
  10.  
  11. All rights reserved.
  12.  
  13.  
  14. COMPILER VERSION 
  15.  
  16. This diskette contains version 2.2 (revision level 117) of the Small C 
  17. compiler as implemented under PC/MS-DOS 2.1 (and later versions) by 
  18. James E.  Hendrix.  This version differs from 2.1 primarily in that the 
  19. code generating and optimizing parts of the compiler have been 
  20. extensively rewritten, making them much more lucid and noticably 
  21. improving the quality of the code generated.  The source files have been 
  22. reorganized into a more logical arrangement.  No new features have been 
  23. added.  
  24.  
  25. Compared to the previous release (version 2.1, revision level 75), this 
  26. compiler generates programs with EXE files that are between 4% and 13% 
  27. (typically 10%) smaller and TWICE as fast.  Although much more 
  28. optimizing is done, the compiler itself is about 6% smaller and runs 
  29. slightly faster than the previous version.  About one fourth of its time 
  30. is spent optimizing.  
  31.  
  32. The main reason for the doubling of the speed of programs compiled with 
  33. Small C is a revision to the library function iscons() so that it calls 
  34. DOS only for the first refererence to a file, thereafter it returns a 
  35. value based on its memory of DOS's original answer.  It turned out that 
  36. this was a very very slow DOS call, and since iscons() is called in 
  37. fgets(), fgetc(), and _read(), which form a thread, the penalty was 
  38. high.  So, not surprisingly, avoiding this DOS call on a byte-by-byte 
  39. basis yielded spectacular improvements in read times.  
  40.  
  41. Another reason for the speed improvement is a rewrite of the character 
  42. classification functions -- isalpha(), isdigit(), etc.  Whereas they 
  43. used to test a character's value with "if" statements, they now simply 
  44. reference an array with the questionable character as a subscript and 
  45. return a bit indicating whether or not the character is of the specified 
  46. class.  This sped up these functions by THREE times.  Since these 
  47. functions are now so small, they have been grouped into a single source 
  48. module IS.C.  
  49.  
  50. Finally, there is the general improvement in speed produced by the 
  51. additional code optimizing, which goes far beyond what was being done.  
  52. While not as good as the major C compilers, the code Small C now 
  53. generates is quite respectable.  For example, AR.EXE is 1.13 times the 
  54. size of the same program compiled with Microsoft 4.0.  
  55.  
  56. For those interested in studying the compiler itself, perhaps the nicest 
  57. thing about version 2.2 is the rewrite of the code generation and 
  58. optimizing logic, the reorganization of the source files, and the 
  59. revised p-code names.  These changes have made the compiler much more 
  60. understandable.  First, the p-code names now follow a system so that it 
  61. is possible to tell exactly what a code does without looking at the 
  62. assembly text it generates.  The regrouping of the source code clearly 
  63. differentiates between front end, back end, and parsing functions.  All 
  64. of the p-codes appear alphabetically in the function setcodes() together 
  65. with the assembly strings they generate, making it unnecessary to forage 
  66. around for the exact effect of a p-code.  Finally, the peephole 
  67. optimizer has been generalized to take both the p-code sequence to be 
  68. matched and the optimizing instructions from integer arrays to which it 
  69. is directed.  A single array contains both of these for a given 
  70. optimization case.  One can easily understand the optimizations by 
  71. studying these arrays -- which are initialized with p-code symbols and 
  72. other symbols that form a kind of language.  There is no need to study 
  73. the optimizer itself to read these optimization actions.  
  74.  
  75. This version fixes a number of problems with the earlier version -- most 
  76. notably, a tendency of scanf() to drop characters.  Read the file 
  77. HISTORY for a complete listing of the revisions since 2.1.  
  78.  
  79.  
  80. ASSEMBLER VERSION
  81.  
  82. This diskette contains an executable copy of version 1.0 (revision level 
  83. 0) of the Small Assembler.  This is an assembler written in Small C 
  84. primarily for use in processing Small C output.  At this stage in its 
  85. development, the assembler is not yet fully developed, and runs quite 
  86. slowly compared to Microsoft's latest assembler (version 5.1).  But it 
  87. is adequate for use with Small C, making it unnecessary to purchase 
  88. an expensive assembler.  If all goes well, by the fall of 1988 the Small 
  89. Assembler will be released as a product in its own right -- complete 
  90. with source code and a user's manual.  Still later, a book (along the 
  91. lines of "A Small C Compiler") is to be published.  It will fully treat 
  92. assembly language programming, use of the Small Assembler, and its 
  93. theory and design.  
  94.  
  95. This assembler is essentially compatible with the Microsoft product.  
  96. Either may be used with the Small C compiler.  Differences are 
  97. primarily: (1) many Microsoft directives are not supported (most notably 
  98. the conditional assembly directives), (2) macros employ positional 
  99. rather than named parameters, (3) not all of the Microsoft expression 
  100. operators are supported, and (4) most of the expression operators in the 
  101. C language are supported.  
  102.  
  103. Since this is the initial release of the Small Assembler, I would not be 
  104. surprised to learn of problems.  So, keep your eyes open and let me know 
  105. of any trouble you have.  If you want a response, then be sure to 
  106. enclose a self addressed, stamped envelope.  My address is: 
  107.  
  108.                         James E. Hendrix
  109.                         P.O. Box 1435
  110.                         Oxford, MS  38655
  111.  
  112.  
  113. THE DISTRIBUTION DISKETTE
  114.  
  115. The following files are included on this disk: 
  116.  
  117.    READ.ME       This documentation.
  118.    REGISTER      User registration form.
  119.    ORDER         "Small" software order form.
  120.    HISTORY       History of Small C rivisions.
  121.    CCC.BAT       Procedure to compile the compiler.
  122.    CC.EXE        Executable Small C compiler.
  123.    CC.H          Header file for compiling Small C.
  124.    CC1.C         Small C source (part 1).
  125.    CC2.C         Small C source (part 2).
  126.    CC3.C         Small C source (part 3).
  127.    CC4.C         Small C source (part 4).
  128.    NOTICE.H      Copyright header for compiling Small C.
  129.    STDIO.H       Standard header file for all compiles.
  130.    CLIB.LIB      Small C object library for use with LINK.
  131.    CLIB.ARC      Small C library source archive.
  132.    CLIBARC.LST   List supplied to AR for building CLIB.ARC.
  133.    AR.EXE        Executable archive maintainer.
  134.    AR.C          Archive maintainer source.
  135.    ASM.EXE       Executable Small Assembler.
  136.  
  137.  
  138. DOCUMENTATION
  139.  
  140. The Small C compiler is fully described in "A Small C Compiler: 
  141. Language, Usage, Theory, and Design"  by James E. Hendrix.  Copies are 
  142. available from: 
  143.  
  144.                      M&T Publishing, Inc.
  145.                      501 Galveston Dr.
  146.                      Redwood City, CA  94063
  147.                      Phone: 1 (800) 533-4372
  148.  
  149. In this book, you will find a full treatment of the Small-C language, 
  150. the use of the Small-C compiler, and the theory of operation of the 
  151. compiler.  It documents revision level 112 of the compiler.  Any 
  152. additional revisions to the compiler on this diskette are described in 
  153. the file named HISTORY.  
  154.  
  155. Until the assembler is released as a separate product, its only 
  156. documentation is that which is found here in this file.  
  157.  
  158.  
  159. USING THE COMPILER
  160.  
  161. The Small-C compiler takes in a subset of the full C language, and 
  162. generates Microsoft assembly language output.  It supports only integer 
  163. and character data types.  Arrays are limited to one dimension.  It does 
  164. not support arrays of pointers, structures, or unions.  Also lacking are 
  165. sizeof, casts, #if expr, #undef, and #line. External functions are 
  166. automatically declared, but external variables (defined in another 
  167. source file) must be declared explicitly.  Functions always return 
  168. integer values. Globals may be initialized using the = syntax, but 
  169. locals cannot be initialized. Locals are always automatic, and the 
  170. specifiers auto, static, extern, register, and typedef are not accepted 
  171. at the local level. Only extern is accepted at the global level. 
  172. Character variables are expanded with sign-extension when they are 
  173. referenced; character constants are not sign extended, however.  
  174.  
  175. The steps involved in compiling a program are documented in the file 
  176. C.BAT.  
  177.  
  178. Examples of invoking the compiler follow: 
  179.  
  180.   CC                       compile console input
  181.                            giving console output
  182.  
  183.   CC <FILE1 -L1 -P         compile FILE1 giving console
  184.                            output, list the source as
  185.                            comments in the output, and
  186.                            pause on errors
  187.  
  188.   CC <FILE1 >FILE2 -M      compile FILE1 giving FILE2
  189.                            and monitor progress by
  190.                            listing function headers on
  191.                            the console
  192.  
  193.   CC FILE1                 compile FILE1.C giving FILE1.ASM
  194.  
  195.   CC FILE1 FILE2           compile FILE1.C then FILE2.C
  196.                            giving FILE1.ASM
  197.  
  198.   CC FILE1 FILE2 >FILE3    compile FILE1.C then FILE2.C into
  199.                            a single program in FILE3
  200.  
  201.   CC FILE1 >FILE2 -NO -A   compile FILE1.C giving FILE2,
  202.                            negate optimizing, and 
  203.                            sound the alarm on errors
  204.  
  205. Any number of files may be concatenated as input by listing them in the 
  206. command line; in that case stdin is not used. Standard DOS file 
  207. specifications, including logical devices, are accepted. The listing 
  208. switch has two forms: 
  209.  
  210.           -L1   lists on stdout (with output) as comments
  211.           -L2   lists on stderr (always the console)
  212.  
  213. If the compiler aborts with an exit code of 1, there is insufficient 
  214. memory to run it.  Pressing control-S makes the compiler pause until 
  215. another key is pressed, and control-C aborts the run with an exit code 
  216. of 2.  Press ENTER to resume execution after a pause because of a 
  217. compile error. If input is from the keyboard,  control-Z  indicates end-
  218. of-file, control-X rubs out the pending line, and Backspace rubs out the 
  219. previous character.  
  220.  
  221.  
  222. USING THE ASSEMBLER
  223.  
  224. The Small Assembler reads an ASCII source file and writes an object file 
  225. in the standard .OBJ file format.  This makes the Small Assembler 
  226. compatible with LINK which comes with PC/MS-DOS.  In fact, Small 
  227. Assembler has no linker of its own; it must be used with the DOS linker.  
  228.  
  229. The command line for invoking the assembler has the following format:
  230.  
  231.           ASM source [object] [-C] [-L] [-NM] [-P] [-S#]
  232.  
  233. Command-line arguments may be given in any order.  Switches may be 
  234. introduced by a hyphen or a slash.  The brackets indicate optional 
  235. arguments; do not enter the brackets themselves.  
  236.  
  237.  source   Name of the source file to be assembled.  The default, and 
  238.           only acceptable, extension is ASM.  Drive and path may be 
  239.           specified.  
  240.  
  241.  object   Name of the object file to be output.  It must have a OBJ 
  242.           extension to be recognized as the output file.  Drive and path 
  243.           may be specified.  If no object file is specified, output will 
  244.           go to a file bearing the same name and path as the source 
  245.           file, but with a OBJ extension.  
  246.  
  247.  -C       Use case sensitivity.  Without this switch, all symbols are 
  248.           converted to upper-case.  With this switch, they are taken as 
  249.           is; upper- and lower-case variants of the same letter are 
  250.           considered to be different.  With or without this switch, 
  251.           segment, group, and class names are always converted to upper-
  252.           case in the output OBJ file.  
  253.  
  254.               Note: The .CASE directive may be included at the
  255.               beginning of the source file to produce the same
  256.               effect as this switch.
  257.  
  258.  -L       Generate an assembly listing on the standard output file.  If 
  259.           you do not want the listing to go to the screen, then provide 
  260.           a redirection specification (e.g., >prn or >abc.lst) to send 
  261.           it whereever you wish.  
  262.  
  263.  -NM      No macro processing.  This speeds up the assembler somewhat.  
  264.           Macro processing is NOT needed for Small-C output files.  
  265.  
  266.  -P       Pause on errors waiting for an ENTER keystroke.
  267.  
  268.  -S#      Set symbol table size to accept # symbols.  Default is 1000.
  269.  
  270. If an illegal switch is given, the assembler aborts with the message
  271.  
  272.         Usage: ASM source [object] [-C] [-L] [-NM] [-P] [-S#]
  273.  
  274. The null switch (- or /) can be used to force this message.
  275.  
  276. If the assembler aborts with an exit code of 1, there is insufficient 
  277. memory to run it.  Pressing control-S makes the assembler pause until 
  278. another key is pressed, and control-C aborts the run with an exit code 
  279. of 2.  Press ENTER to resume execution after a pause because of an 
  280. error.  
  281.  
  282. Symbols (names of labels, etc.) may be up to 31 characters long.  Every 
  283. character has significance.  Symbols may contain the following 
  284. characters: 
  285.  
  286.         1. alphabetic
  287.         2. numeric
  288.         3. the special characters _, $, ?, and @.
  289.  
  290. Labels must be terminated by a colon.  All other names which begin a 
  291. line must not have a colon.  
  292.  
  293. Comments begin with a semicolon (;) and continue to the end of the line.  
  294.  
  295. ASCII strings are must be delimited by quotes (") or apostrophies (').  
  296. The backslash (\) may be used to escape the delimiter when it appears 
  297. within the string.  
  298.  
  299. Only integer numbers are recognized by the assembler.  Numeric constants 
  300. must begin with a numeric (decimal) digit.  The default base (radix) for 
  301. numeric constants is decimal.  Bases may be specified explicitely by 
  302. attaching a letter to the right end of the number as follows: 
  303.  
  304.              b or B    binary
  305.              o or O    octal
  306.              q or Q    octal
  307.              d or D    decimal
  308.              h or H    hexadecimal 
  309.  
  310. Expressions may produce the Boolean values 1 for "true" or 0 for 
  311. "false".  This differs from Microsoft which yields FFFFh for "true".  
  312.  
  313. Expression evaluation is done with 32-bit precision.  The low order bits 
  314. are then used according to the needs of the instruciton being generated.  
  315. Expressions may contain the following operators: 
  316.  
  317.         (highest precedence)
  318.         -------------------------------------  unary operators
  319.         BYTE  PTR      take following operand as a byte
  320.         WORD  PTR      take following operand as a word (2 bytes)
  321.         DWORD PTR      take following operand as a double word (4 bytes)
  322.         FWORD PTR      take following operand as a far word (6 bytes)
  323.         QWORD PTR      take following operand as a quad word (8 bytes)
  324.         NEAR  PTR      consider the following label near
  325.         FAR   PTR      consider the following label far
  326.         OFFSET         the offset to the follownig operand
  327.         SEG            the segment address of the following operand
  328.         xS:            segment register override (e.g. ES:)
  329.         [  ]           indirect memory reference
  330.         !              Logical not
  331.         -              minus
  332.         ~              one's complement
  333.         NOT            one's complement
  334.         ------------------------------------- 
  335.         *              multiplication
  336.         /              division
  337.         %              modulo
  338.         MOD            modulo
  339.         ------------------------------------- 
  340.         .              addition of indirect reference displacement
  341.         +              addition
  342.         -              subtraction
  343.         ------------------------------------- 
  344.         <<             shift left
  345.         >>             shift right
  346.         ------------------------------------- 
  347.         !=             not equal
  348.         NE             not equal
  349.         <=             less than or equal
  350.         LE             less than or equal
  351.         <              less than
  352.         LT             less than
  353.         >=             greater than or equal
  354.         GE             greater than or equal
  355.         >              greater than
  356.         GT             greater than
  357.         ==             equal
  358.         EQ             equal
  359.         ------------------------------------- 
  360.         &              bitwise AND
  361.         AND            bitwise AND
  362.         ------------------------------------- 
  363.         ^              bitwise exclusive OR
  364.         XOR            bitwise exclusive OR
  365.         ------------------------------------- 
  366.         |              bitwise inclusive OR
  367.         OR             bitwise inclusive OR
  368.         ------------------------------------- 
  369.         (lowest precedence)
  370.  
  371. Notice that these precedence levels agree with the C language and 
  372. disagree with the Microsoft assembler.  This should only rarely be a 
  373. problem, however, since most expressions are very simple.  Nevertheless, 
  374. parentheses may be used to override the default precedences.  
  375.  
  376. The dollar sign ($) represents the value of the location counter at the 
  377. beginning of the current instruction.  
  378.  
  379. This version of the assembler knows only the instruction set of the 8086 
  380. processor.  It does not know the 8087 instructions.  Future editions 
  381. will know all of the 80x86 processors and their coprocessors.  
  382.  
  383. The following directives are recognized by this verson of the assembler.  
  384. Only the parameter values shown are supported, however.  
  385.  
  386.      -------------------------------------------------
  387.             .CASE          (see the -C switch above)
  388.      -------------------------------------------------
  389.      name   EQU constantexpression
  390.      alias  EQU symbol
  391.      -------------------------------------------------
  392.      name   =  constantexpression
  393.      -------------------------------------------------
  394.      name   MACRO
  395.             ...
  396.             ENDM
  397.      -------------------------------------------------
  398.      name   SEGMENT  [align]  [combine]  [class]
  399.                       BYTE     PUBLIC     'name'
  400.                       WORD     STACK
  401.                       PARA     COMMON
  402.                       PAGE
  403.             ...
  404.             ENDS
  405.      -------------------------------------------------
  406.      name   GROUP segmentname,,,
  407.      -------------------------------------------------
  408.      name   PROC [distance]
  409.                   NEAR
  410.                   FAR
  411.             ...
  412.             ENDP
  413.      -------------------------------------------------
  414.             ASSUME NOTHING
  415.             ASSUME register:name,,,
  416.                    CS       segmentname
  417.                    SS       groupname
  418.                    DS       NOTHING
  419.                    ES
  420.                    FS
  421.                    GS
  422.      -------------------------------------------------
  423.             PUBLIC name,,,
  424.      -------------------------------------------------
  425.             EXTRN name:type,,,
  426.                        BYTE
  427.                        WORD
  428.                        DWORD
  429.                        FWORD
  430.                        QWORD
  431.                        NEAR
  432.                        FAR
  433.      -------------------------------------------------
  434.      [name] DB expression,,,
  435.      [name] DW expression,,,
  436.      [name] DD expression,,,
  437.      [name] DF expression,,,
  438.      [name] DQ expression,,,
  439.      -------------------------------------------------
  440.             ORG expression
  441.      -------------------------------------------------
  442.             END [start]
  443.      -------------------------------------------------
  444.      name   MACRO
  445.      -------------------------------------------------
  446.             ENDM
  447.      -------------------------------------------------
  448.  
  449. Macro definitions begin with the MACRO directive and end with the ENDM 
  450. directive as shown above.  Macro definitions cannot be nested; however, 
  451. macro expansions (or calls) can.  Since macro arguments are not named, 
  452. none appear with the MACRO directive.  Within the body of the macro, the 
  453. symbol ?1 indicates places where the first argument of the macro call is to 
  454. go.  Likewise, ?2 designates locations where the second argument goes, 
  455. and so forth through ?0 for the 10th argument.  Macro argument 
  456. substitution is done without regard to context, so you are not limited 
  457. to replacing whole symbols with an argument.  For instance, you might 
  458. write J?0 for the mnemonic of a conditional jump.  The first argument of 
  459. the call might be LE, resulting in a mnemonic of JLE.  
  460.  
  461. To avoid "Redundant Definition" errors when a macro containing labels is 
  462. called more than once, you may write labels within the body of a macro 
  463. as @n, where n is a decimal digit.  This allows ten such labels per 
  464. macro.  The assembler maintains a running count of such labels as 
  465. assembly progresses.  Whenever such a label is found in a macro 
  466. expansion, it is replaced by a label of the form @x, where x is the 
  467. running count.  
  468.  
  469. Small Assembler makes no distinction between warnings and hard errors.  
  470. If it issues any error messages in a run, then it finishes the run with 
  471. an exit code of 10 which can be tested by means of an IF statement in a 
  472. batch file.  In that case, it also deletes the OBJ file so that you 
  473. cannot attempt to link and execute an erroneous program.  The following 
  474. error messages may be issued by the assembler: 
  475.  
  476.    Per Run
  477.  
  478.    - No Source File        no input file is specified or it doesn't exist
  479.    - Error in Object File  an error occurred wirting the OBJ file
  480.    - Missing ENDM          the program ended within a macro definition
  481.    - Missing END           the program ended without an END directive
  482.    - Deleted Object File   the OBJ file was deleted because of errors
  483.  
  484.    Per Segment
  485.  
  486.    - CS Not Assumed for    
  487.      this Segment          there is no ASSUME for CS and this segment
  488.  
  489.    Per Line
  490.  
  491.    - Phase Error           the address of a label differs between passes
  492.    - Bad Expression        an expression is written improperly
  493.    - Invalid Instruction   this mnemonic/operand combination is not defined
  494.    - Redundant Definition  the same symbol is defined more than once
  495.    - Bad Symbol            a symbol is improperly formed
  496.    - Relocation Error      an relocatable address is written as absolute
  497.    - Undefined Symbol      an undefined symbol is referenced
  498.    - Bad Parameter         a macro call does not give a required parameter
  499.    - Range Error           a self-relative reference is too distant
  500.    - Syntax Error          an instruction or directive is improperly formed
  501.    - Not Addressable       "END xxx" has something other than an address
  502.    - Segment Error         a segment is not defined or referenced properly
  503.    - Procedure Error       a procedure is not defined properly
  504.  
  505.  
  506. USING THE ARCHIVE MAINTAINER
  507.  
  508. Comments in the front of AR.C describe the operation of the archive 
  509. maintainer AR.EXE.  To extract all of the modules out of the library 
  510. archive, enter the command: 
  511.  
  512.                           AR -X CLIB.ARC
  513.